<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>1.逛水果店</title>
  </head>
  <body>
    <div id="app">
      <h1>欢迎光临_vue开发的收银系统_水果店</h1>
      <p>苹果 10￥ / 斤, 折扣 < 8折 ></p>
      请输入你要买的斤数
      <input type="number" v-model="weight" />
      <button @click="calculate">结账买单~</button>
      <div>
        <p>
          结账单: 总价: {{ totalPrice }}￥ 折后价: {{ discountedPrice }}￥ 省了:
          {{ savings }}￥
        </p>
      </div>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          weight: 0,
          price: 10,
          disCount: 0.8,
          totalPrice: 0,
          discountedPrice: 0,
          savings: 0,
        },
        methods: {
          calculate() {
            this.totalPrice = this.weight * this.price;
            this.discountedPrice = this.disCount * this.weight * this.price;
            this.savings = this.totalPrice - this.discountedPrice;
          },
        },
      });
    </script>
  </body>
</html>
